﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Eis51.CampanyCMS.FrameWork;
using Eis51.CampanyCMS.Business.Bus;
using Eis51.CampanyCMS.Business.BaseInfoMng;
using Eis51.Web.Admin;

namespace Eis51.CampanyCMS.WebUI.Admin.Coupon
{
    public partial class CouponPage : BasePage
    {

        public int CouponId
        {
            get
            {
                if (Request.QueryString["CouponId"] != null)
                {
                    return int.Parse(Request.QueryString["CouponId"]);
                }
                return 0;
            }
        
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (this.CouponId <= 0)
                {
                    txtCouponNo.Text = CouponBLL.GetInstance().LiuShuiNo();
                }
                ShowData();
            }
        }

        private void ShowData()
        {
            Eis51.CampanyCMS.Model.Bus.Coupon  c = CouponBLL.GetInstance().Get(new Eis51.CampanyCMS.Model.Bus.Coupon.Key(CouponId));
            if (c != null)
            {
                UControl.CopyEntityToControl(this.Page.Form, c);
            }

        }


        private bool Save()
        {

            Eis51.CampanyCMS.Model.Bus.Coupon c = CouponBLL.GetInstance().Get(new Eis51.CampanyCMS.Model.Bus.Coupon.Key(CouponId));

            if (c == null)
            {
                c = new Eis51.CampanyCMS.Model.Bus.Coupon();
            }
            UControl.CopyControlToEntity(this.Page.Form, c);
            return CouponBLL.GetInstance().Subimt(c);
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            Save();
            Response.Redirect("CouponList.aspx");
        }

        protected void bntget_Click(object sender, EventArgs e)
        {
            txtCouponNo.Text = CouponBLL.GetInstance().LiuShuiNo();
        }
    }
}
